package com.foreveross;

import com.foreveross.repository.ProductRepository;
import com.foreveross.security.domain.User;
import com.foreveross.security.service.rpc.api.UserService;
import com.foreveross.service.impl.ProductServiceImpl;
import org.junit.Before;
import org.junit.Test;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;

import static junit.framework.TestCase.assertNotNull;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;

/**
 * Created by shao_win on 2016/7/5.
 */
public class BookPubApplicationTests_TDD {

    @Mock
    private UserService userService;

    @Mock
    private ProductRepository productRepository;

    private ProductServiceImpl productServiceImpl;

    @Before
    public void setupMockMvc() {
        MockitoAnnotations.initMocks( this );
        productServiceImpl=new ProductServiceImpl(productRepository,userService);
    }

    @Test
    public void testRPCService(){
        System.out.println("RPC Service测试开始");
        User u=new User();
        u.setId(1);
        u.setUsername("shao_win");
        when(userService.findByToken("aaa")).thenReturn(u);
        User user= (User) productServiceImpl.findUserByToken("aaa");
        System.out.println("username="+user.getUsername());
        verify( userService ).findByToken("aaa");
        assertNotNull(user);
    }

}